/**
 * 2
 *  
 * @Author : Ruoyu Wang
 * @DateTime : 24-9-22 上午9:43
 */

#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, m, q;
    cin >> n >> m >> q;

    vector<long long> row(n);
    vector<long long> leftMap(n, 0);

    for (int i = 0; i < n; ++i) {
        row[i] = i;
    }

    while (q--) {
        long long t, x, y;
        cin >> t >> x >> y;
        x--;
        if (t == 1) {
            y--;
            swap(row[x], row[y]);
        } else if (t == 2) {
            leftMap[row[x]] = (leftMap[row[x]] + y) % m;
        } else if (t == 3) {
            y--;
            long long yy = (y + leftMap[row[x]]) % m;
            cout << row[x] * m + yy + 1 << endl;
        }
    }

    return 0;
}
